package top.ffhome.game.ch04;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimerTest extends JFrame implements ActionListener {
    private JLabel jlTime = new JLabel();
    private Timer timer;

    public TimerTest() {
        setTitle("Timer测试");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(180, 80);
        add(jlTime);
        timer = new Timer(500, this);
        timer.start();
        setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        jlTime.setText(format.format(date));
    }

    public static void main(String[] args) {
        new TimerTest();
    }
}
